#ifndef __BHTTP_BTHREAD_H__
#define __BHTTP_BTHREAD_H__
#pragma once

#include <string>
#include <memory>
#include <thread>
#include <atomic>
#include <functional>

namespace bhttp
{

class bthread
{
	using bthread_func = std::function<void()>;
	using bthread_ptr = std::shared_ptr<std::thread>;
public:
	bthread(const bthread&) = delete;
	bthread& operator=(const bthread&) = delete;

	explicit bthread(const bthread_func& func, const std::string& name = std::string());
	explicit bthread(bthread_func&& func, const std::string& name = std::string());
	~bthread();

	void start();
	void join();

private:
	bthread_ptr thd_;
	bthread_func func_;
	std::string name_;
	bool started_{ false };
	bool joined_{ false };

	static std::atomic<int> num_created_;
};

}

#endif // __BHTTP_THREAD_H__
